﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class HisSpouseBLL : IHisSpouseBLL
    {
        private static readonly IHisSpouseDAL dal = DataAccess.CreateHisSpouses();

        private HisSpouseInfo hisInfo = new HisSpouseInfo();
        private EmployeeInfo empInfo = new EmployeeInfo();
        private PersonInfo personInfo = new PersonInfo();
        private MasNamePrefixInfo pfInfo = new MasNamePrefixInfo();

        public DataTable ListHisSpousesDataTable(string Employee)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            hisInfo.Employee = empInfo;
            return dal.ListHisSpousesDataTable(hisInfo);
        }

        public IList<HisSpouseInfo> ListHisSpouses(string Employee)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            hisInfo.Employee = empInfo;
            return dal.ListHisSpouses(hisInfo);
        }

        public IList<HisSpouseInfo> ListHisSpousesBySequence(string Sequence)
        {
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return dal.ListHisSpouses(new HisSpouseInfo(Seq));
        }
        public DataSet LoadSpouse(Nullable<int> Sequence, Nullable<int> EmployeeSequence)
        {
                return dal.LoadSpouse(Sequence, EmployeeSequence);
        }
        public void Insert(string Employee, string NamePrefixes, string FirstName, string LastName
            , bool Earning, string Status, string Citizen, string PlaceOfBirth, int CreatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            pfInfo.Sequence = NamePrefixes.Length > 0 ? Int32.Parse(NamePrefixes) : 0;
            personInfo.FirstName = FirstName;
            personInfo.LastName = LastName;
            personInfo.NamePrefix = pfInfo;
            personInfo.Citizen = Citizen;

            var model = new HisSpouseInfo(0, empInfo, personInfo, Earning, Status, "", "", CreatedBy, 0);
            model.PlaceOfBirth = PlaceOfBirth;
            try
            {
                dal.Insert(model);
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Employee, string NamePrefixes, string FirstName, string LastName
            , bool Earning, string Status, string Citizen, string PlaceOfBirth, int UpdatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            pfInfo.Sequence = NamePrefixes.Length > 0 ? Int32.Parse(NamePrefixes) : 0;
            personInfo.FirstName = FirstName;
            personInfo.LastName = LastName;
            personInfo.NamePrefix = pfInfo;
            personInfo.Citizen = Citizen;

            var model = new HisSpouseInfo(Sequence, empInfo, personInfo, Earning, Status, "", "", UpdatedBy, 0);
            model.PlaceOfBirth = PlaceOfBirth;
            try
            {
                dal.Update(model);
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy, string empSeq)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy, empSeq);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
